package com.zhdl;

import com.zhdl.modules.prefiresys.web.service.CollectService;
import com.zhdl.modules.prefiresys.web.service.EventBusResult;
import com.zhdl.modules.protocol_rtu.SerialPortManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;

@Slf4j
@EnableAsync
@EnableScheduling
@SpringBootApplication(scanBasePackages = {"com.zhdl","com.project"})
public class AppApplication extends SpringBootServletInitializer implements ApplicationRunner {

    public static boolean localSoundStatus = true;
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(AppApplication.class);
        app.addListeners(new ApplicationPidFileWriter());
        app.run(args);
    }

    @Override
    protected WebApplicationContext run(SpringApplication application) {
        return super.run(application);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return super.configure(builder);
    }

    @Resource
    private EventBusResult eventBusResult;
    @Resource
    private CollectService collectService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        SerialPortManager.getInstance().addPort("COM5",9600,800);
        SerialPortManager.getInstance().addPort("COM6",9600,800);

        eventBusResult.init();
        collectService.BuildMemDev();
    }

}
